import tkinter as tk
from tkinter import ttk


class SettingsWindow:
    def __init__(self, root):
        # 使用传入的root创建Toplevel窗口
        self.root = root
        self.window = tk.Toplevel(root)
        self.window.withdraw()  # 初始时隐藏窗口
        self.window.title("Find My Mouse Settings")

        # 设置窗口大小和位置
        window_width = 300
        window_height = 150  # 减小窗口高度
        screen_width = self.window.winfo_screenwidth()
        screen_height = self.window.winfo_screenheight()
        center_x = int(screen_width / 2 - window_width / 2)
        center_y = int(screen_height / 2 - window_height / 2)

        self.window.geometry(f'{window_width}x{window_height}+{center_x}+{center_y}')
        self.window.resizable(False, False)

        # 创建样式
        style = ttk.Style()
        style.configure('TLabel', font=('Arial', 12))

        # 创建标题标签
        title_label = ttk.Label(
            self.window,
            text="Find My Mouse",
            font=('Arial', 14, 'bold')
        )
        title_label.pack(pady=20)

        # 创建说明标签
        instruction_label = ttk.Label(
            self.window,
            text="Double-click Left Ctrl to activate",
            font=('Arial', 12)
        )
        instruction_label.pack(pady=10)

        # 设置关闭窗口的行为
        self.window.protocol("WM_DELETE_WINDOW", self.on_closing)

    def show(self):
        """显示设置窗口"""
        self.window.deiconify()

    def hide(self):
        """隐藏设置窗口"""
        self.window.withdraw()

    def on_closing(self):
        """处理窗口关闭事件"""
        self.hide()  # 只隐藏窗口，不退出程序